#include <Winsock2.h>
#include <stdio.h>
#include <iostream>
#include <thread>
#include <future>
#pragma comment(lib,"ws2_32.lib")
using namespace std;
int port;
char* ipadd;
void passage()
{
	WORD wVersionRequested;
	WSADATA wsaData;
	int err;

	wVersionRequested = MAKEWORD(1, 1);

	err = WSAStartup(wVersionRequested, &wsaData);
	if (err != 0)
	{

		return;
	}

	if (LOBYTE(wsaData.wVersion) != 1 ||
		HIBYTE(wsaData.wVersion) != 1)
	{
		WSACleanup();
		return;
	}
	SOCKET sockClient = socket(AF_INET, SOCK_DGRAM, 0);
	SOCKADDR_IN addrSrv;
	addrSrv.sin_addr.S_un.S_addr = inet_addr(ipadd);
	addrSrv.sin_family = AF_INET;

	addrSrv.sin_port = htons(port);
	while (1) {
		sendto(sockClient, "UDPpackage", strlen("UDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackageUDPpackage") + 1, 0,
			(SOCKADDR*)&addrSrv, sizeof(SOCKADDR));
	}
	closesocket(sockClient);
}

int main(int argc, char* argv[])
{
	port = atoi(argv[2]);
	ipadd = argv[1];
	thread t(passage);
	while (1) {
		t.join();
	}
	//cout << ipadd << endl;
	WSACleanup();
}